package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.system.Capabilities;
	import flash.text.TextField;
	
	import nl.sanity.debug.LogConsole;

	public class Main extends Sprite
	{
		public function Main()
		{
			LogConsole.log( "This is a 'log' message" );
			LogConsole.debug( "This is a 'debug' message" );
			LogConsole.info( "This is an 'info' message" );
			LogConsole.warn( "This is a 'warning' message" );
			LogConsole.error( "And this is an 'error' message" );
			
			// You can call LogConsole.send directly. 
			// When the specified level doesn't exist, the default 'log' level will be used.
			LogConsole.sendMessage( "nonExistingLevel", "Message send by directly calling the 'send' method" );
			
			// Send an object to the console so it can be inspected
			var object:Object 	= new Object();
			object.foo 			= { "bar": true };
			LogConsole.sendObject( object );
			
			// Start loading an xlm file. Once loaded this will be sent to the consoler.
			loadXML();
			
			
			var tf:TextField	= new TextField();
			tf.width			= 400;
			tf.height			= 300;
			tf.multiline		= true;	
			addChild( tf );
			
			tf.appendText( " debug player: " + Capabilities.isDebugger );
			tf.appendText( "\n ExternalInterface available: " + ExternalInterface.available );
			tf.appendText( "\n isBrowser: " + LogConsole.isBrowser() );
			tf.appendText( "\n isFireBug: " + LogConsole.isFireBug() );
		}
		
		protected function loadXML():void
		{
			LogConsole.info( "Start loading XML" );
			var loader:URLLoader 	= new URLLoader();
			loader.addEventListener( Event.COMPLETE, onXMLLoaded );
			
			loader.load( new URLRequest( "assets/logconsole.xml" ) );
		}
		
		protected function onXMLLoaded( event:Event ):void
		{
			LogConsole.info( "XML loaded" );
			
			var loader:URLLoader	= event.target as URLLoader;
			var xml:XML 			= XML( loader.data );
			
			LogConsole.sendXML( xml );
		}
		
		
	}
}
